import handlers from "./handlers";

export default function threeParser(command) {
  try {
    const [action, subAction, rawPara] = command.split(" ");
    const para = rawPara.split(",");
    for (const fn of handlers[action][subAction]) {
      const obj = fn(...para);
      if (obj !== null) return obj;
    }
  } catch (error) {
    if (error.name === "TypeError") {
      throw "Error: 错误的命令格式";
    } else {
      throw error;
    }
  }
  throw "Error: 没有匹配的处理程序";
}
